package com.gosophia.conferenceManagement.scheme.test.integration;

import java.util.Date;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional;
import junit.framework.Assert;
import com.gosophia.commons.exception.BusinessException;
import com.gosophia.conferenceManagement.common.entity.Document;
import com.gosophia.conferenceManagement.scheme.entity.SchemeTransientStore;
import com.gosophia.conferenceManagement.scheme.service.ConferenceSchemeService;
import com.gosophia.dataDictionary.entity.DataValue;
import com.gosophia.dataDictionary.service.DataDictionaryService;
import com.gosophia.userManagement.entity.UserInfo;
import com.gosophia.userManagement.service.UserManagementService;
@ContextConfiguration(locations = { "classpath*:moduleContext.xml","classpath:applicationContext-it.xml" })
@Transactional(rollbackFor = { BusinessException.class })
public class ITConferenceSchemeServiceImpl extends AbstractTransactionalJUnit4SpringContextTests {
   
	@Autowired
	private ConferenceSchemeService conferenceSchemeService;
	
	@Autowired
	private UserManagementService userManagementService;
	
	@Autowired
	private DataDictionaryService dataDictionaryService;
	
	@Test
	public void test(){
		System.out.println(conferenceSchemeService);
	}
	/**
	 * 测试schemeTransientStore实体保存
	 * @throws BusinessException 
	 */
	@Test
	public void testSaveOrUpdateSchemeTransientStoreByNormal() throws BusinessException{
		SchemeTransientStore schemeTransientStore = new SchemeTransientStore();
		schemeTransientStore.setConferenceName("会议信息暂存");
		DataValue dataValue = dataDictionaryService.findDataValueByDataValueId(1012L);
		schemeTransientStore.setImportance(dataValue);
		schemeTransientStore.setPlanEndDate(new Date(new Date().getTime()+15*24*3600*1000));
		schemeTransientStore.setDescription("会议信息暂存测试描述");
		Document schemeDocument = new Document();
		schemeDocument.setDocumentId(1L);
		schemeTransientStore.setSchemeDocument(schemeDocument);
		schemeTransientStore.setNextStep("定稿");
		UserInfo commandPerson = userManagementService.findUserInfoByUserInfoId(1L);
		schemeTransientStore.setCommandPerson(commandPerson);
		schemeTransientStore.setNote("测试没有ID的情况");
		UserInfo creator = userManagementService.findUserInfoByUserInfoId(1000L);
		schemeTransientStore.setCreator(creator);
		schemeTransientStore.setCreatDate(new Date());
		//先不加jobId
		Long  id = conferenceSchemeService.saveOrUpdateSchemeTransientStore(schemeTransientStore);
		Assert.assertNotNull(id);
	}
	/**
	 * 测试schemeTransientStore有Id情况的实体保存
	 * @throws BusinessException 
	 */
	@Test
	public void testSaveOrUpdateSchemeTransientStoreById() throws BusinessException{
		SchemeTransientStore schemeTransientStore = new SchemeTransientStore();
		schemeTransientStore.setSchemeTransientStoreId(1000L);
		schemeTransientStore.setConferenceName("会议信息暂存");
		DataValue dataValue = dataDictionaryService.findDataValueByDataValueId(1012L);
		schemeTransientStore.setImportance(dataValue);
		schemeTransientStore.setPlanEndDate(new Date(new Date().getTime()+15*24*3600*1000));
		schemeTransientStore.setDescription("会议信息暂存测试描述");
		Document schemeDocument = new Document();
		schemeDocument.setDocumentId(1L);
		schemeTransientStore.setSchemeDocument(schemeDocument);
		schemeTransientStore.setNextStep("定稿");
		UserInfo commandPerson = userManagementService.findUserInfoByUserInfoId(1L);
		schemeTransientStore.setCommandPerson(commandPerson);
		schemeTransientStore.setNote("测试没有ID的情况");
		UserInfo creator = userManagementService.findUserInfoByUserInfoId(1000L);
		schemeTransientStore.setCreator(creator);
		schemeTransientStore.setCreatDate(new Date());
		//先不加jobId
		Long  id = conferenceSchemeService.saveOrUpdateSchemeTransientStore(schemeTransientStore);
		Assert.assertSame(id, schemeTransientStore.getSchemeTransientStoreId());
	}
	/**
	 * 测试DeleteSchemeTransientStore方法
	 * @throws BusinessException
	 */
	@Test
	public void testDeleteSchemeTransientStoreByNormal()throws BusinessException{
		SchemeTransientStore schemeTransientStore = new SchemeTransientStore();
		schemeTransientStore.setConferenceName("会议信息暂存");
		DataValue dataValue = dataDictionaryService.findDataValueByDataValueId(1012L);
		schemeTransientStore.setImportance(dataValue);
		schemeTransientStore.setPlanEndDate(new Date(new Date().getTime()+15*24*3600*1000));
		schemeTransientStore.setDescription("会议信息暂存测试描述");
		Document schemeDocument = new Document();
		schemeDocument.setDocumentId(1L);
		schemeTransientStore.setSchemeDocument(schemeDocument);
		schemeTransientStore.setNextStep("定稿");
		UserInfo commandPerson = userManagementService.findUserInfoByUserInfoId(1L);
		schemeTransientStore.setCommandPerson(commandPerson);
		schemeTransientStore.setNote("测试没有ID的情况");
		UserInfo creator = userManagementService.findUserInfoByUserInfoId(1000L);
		schemeTransientStore.setCreator(creator);
		schemeTransientStore.setCreatDate(new Date());
		schemeTransientStore.setJobId(1L);
		Long  id = conferenceSchemeService.saveOrUpdateSchemeTransientStore(schemeTransientStore);
		conferenceSchemeService.deleteSchemeTransientStore(id);
		if(conferenceSchemeService.findTransientStoreByJobId(1L)==null){
			Assert.assertTrue(true);
		}
		
	}
	/**
	 * 测试findTransientStoreByJobId方法
	 * @throws BusinessException
	 */
	@Test
	public void testFindTransientStoreByJobIdNormal() throws BusinessException{
		SchemeTransientStore schemeTransientStore = conferenceSchemeService.findTransientStoreByJobId(1L);
		Assert.assertEquals("定稿", schemeTransientStore.getNextStep());
	}
}
